< previous page page_658 next page >

Page 658
Private Sub Form_Load()
    ' get instance ID
    cName = InputBox("Enter Job Name:")
    Me.Caption = cName
    '
    ' load db and open set
    Set db = OpenDatabase("C:\TYSDBVB5\SOURCE\DATA\MULTIUSE.MDB")
    Set rs = db.OpenRecordset("mastertable", dbOpenTable, dbSeeChanges)
    '
    ' count total recs in set
    rs.MoveLast
    nMax = rs.RecordCount
    '
End Sub
Now add the following two code pieces to the Click events of the option buttons. These routines toggle the LockEdits property of the Recordset between pessimistic locking (LockEdits=True) and optimistic locking (LockEdits=False).
This code snippet turns on pessimistic locking:
Private Sub Option1_Click()
    If Option1 = True Then
        rs.LockEdits = True
    Else
        rs.LockEdits = False
    End If
End Sub
This code snippet turns on optimistic locking:
Private Sub Option2_Click()
    If Option2 = True Then
        rs.LockEdits = False
    Else
        rs.LockEdits = True
    End If
End Sub
Finally, add the following code to the cmdEdit_Click event of the form. While in Edit mode, this code prompts you for a record number. It then moves to that record, invokes the Edit method, makes a forced change in a Recordset field, and updates some titles and messages. When the form is in Update mode, this routine attempts to update the Recordset with the changed data and then resets some titles. Here's the code:
Private Sub cmdEdit_Click()
    On Error GoTo cmdEditClickErr   ' set trap
    '
    Dim nRec As Integer ' for rec select
    Dim X As Integer    ' for locator
    '
    ' are we trying to edit?
    If cmdEdit.Caption = "&Edit" Then
        ' get rec to edit
        nRec = InputBox("Enter Record # to Edit [1 - " +

 
< previous page page_658 next page >

If you like this book, buy it!